# Based on https://aur.archlinux.org/packages/mingw-w64-capnproto/
#
# Maintainer: Igor Matuszewski <xanewok@gmail.com>
# Contributors: Dave Reisner <dreisner@archlinux.org>
#               Matthias Blaicher <matthias@blaicher.com>
#               Severen Redwood <severen@shrike.me>
#               Igor Matuszewski <xanewok@gmail.com>

_realname=capnproto
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.8.0
pkgrel=2
pkgdesc="Cap'n Proto serialization/RPC system (mingw-w64)"
arch=('any')
url='https://capnproto.org/'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-openssl")
source=("https://capnproto.org/capnproto-c++-${pkgver}.tar.gz")
sha512sums=('a32dbe6556a95761a5edc55237bd5558cb0ec08127f2fef1712076d5be4cd63e165a5d83b522307336bd3afeed1241f2c1e507830e8f12ac5dec78703a85417f')

prepare() {
  cd "${srcdir}/capnproto-c++-${pkgver}"
}

build() {
  [[ -d "${srcdir}/build-${CARCH}" ]] && rm -rf "${srcdir}/build-${CARCH}"
  mkdir -p "${srcdir}/build-${CARCH}" && cd "${srcdir}/build-${CARCH}"

  ../capnproto-c++-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --disable-shared \
    --enable-static \
    --with-openssl

  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="${pkgdir}" install
}
